package com.service.core.exception;

import com.service.core.constant.BusinessStatus;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * Description: 公共异常处理类
 */
@Setter
@Getter
@ToString
public class CommonException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    private String msg;
    private int code = 500;
    private Object data;


    /**
     * 国际化
     */
    private String i18nKey;


    public CommonException(String msg, String i18nKey) {
        super(msg);
        this.msg = msg;
        this.i18nKey = i18nKey;
    }

    public CommonException(String msg) {
        super(msg);
        this.msg = msg;
    }

    public CommonException(int code, String msg) {
        super(msg);
        this.msg = msg;
        this.code = code;
    }

    public CommonException(int code, String msg, Object data) {
        super(msg);
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public CommonException(int code, String msg, Object data, String i18nKey) {
        super(msg);
        this.msg = msg;
        this.code = code;
        this.data = data;
        this.i18nKey = i18nKey;
    }

    public CommonException(BusinessStatus businessStatus, String i18nKey) {
        super(businessStatus.getReasonPhrase());
        this.msg = businessStatus.getReasonPhrase();
        this.code = businessStatus.value();
        this.i18nKey = i18nKey;
    }

    public CommonException(int code, String msg, Throwable e) {
        super(msg, e);
        this.msg = msg;
        this.code = code;
    }

}
